<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/webUtil.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form  class="definewidth m20" id="reForm">
<input id="resourceId" type="hidden" name="resourceId" value="{$user.id}" />
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">资源名称</td>
            <td><input type="text" name="resourceName" value="挂号信息管理" id="resourceName"/></td>
        </tr>
        <tr>
            <td class="tableleft">url</td>
            <td><input type="text" name="url" value="query.action" id="resourceUrl"/></td>
        </tr>
        <tr>
            <td class="tableleft">是否有效</td>
            <td>
                <input type="radio" name="resourceState" value="0" checked/> 有效
              <input type="radio" name="resourceState" value="1" /> 无效
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="button" class="btn btn-primary" type="button" id="updateResource">更新</button>&nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    $(function () {
        var url = document.location.toString();
        var resourceId = url.GetValue("id");
        var pageNum = url.GetValue("index");
        loadData();
        $('#backid').click(function(){
				window.location.href="index.html?index="+pageNum;
		 });
        function loadData(){
            $.ajax({
                type:"GET",
                url: "/resource/"+resourceId,
                data: "",
                dataType:"json",
                success:function (vo) {
                    var obj = vo.obj;
                    $("#resourceId").val(obj.resourceId);
                    $("#resourceName").val(obj.resourceName);
                    $("#resourceUrl").val(obj.url);
                    $($(".state").eq(obj.resourceState)).prop('checked');
                }
            });
        }
        $("#updateResource").click(function () {
            var resourceName = $("#resourceName").val();
            var resourceUrl = $("#resourceUrl").val();
            if(resourceName.length<=0 || resourceUrl.length<=0){
                alert("不能修改为空！");
                return;
            }
            $.ajax({
                type:"POST",
                url:"/resource",
                data:$("#reForm").serialize()+"&_method=PUT",
                dataType:"json",
                success: function (vo) {
                    if (vo.code == 200){
                        window.location.href="index.html?index="+pageNum;
                    }else {
                        alert(vo.msg);
                    }
                }
            });
        });
    });
</script>